<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__EXTEND__/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__EXTEND__/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__EXTEND__/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>

    <![endif]-->
    <title>编辑宝贝分类 - 宝贝管理</title>

</head>
<body>
<article class="page-container">
    <span style="color:gray;fone-size:1.2em">宝贝分类编辑</span>
    <form class="form form-horizontal" id="form-admin-edit">
        <input type="hidden" name="id" value="{{$data['id']}}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类ID：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" disabled  value="{{$data['id']}}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>上级分类：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="select-box">
                    <select name="pid" class="select">
                        <option value="0">顶级分类</option>
                        <foreach name="pids" item="pid">
                            <if condition="$pid['level'] gt 1">
                                <option value="not" <if condition="$data['pid'] eq $pid['id']">selected</if>>{{:str_repeat("&nbsp;&nbsp;|--&nbsp;",$pid['level'])}}{{$pid['name']}}</option>
                                <else/>
                                <option value="{{$pid['id']}}" <if condition="$data['pid'] eq $pid['id']">selected</if> >{{:str_repeat("&nbsp;&nbsp;|--&nbsp;",$pid['level'])}}{{$pid['name']}}</option>
                            </if>
                        </foreach>
                    </select>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="name" name="name" value="{{$data['name']}}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="status" type="radio" id="status-0"  value="0" <if condition="$data['status'] eq 0">checked</if>>
                    <label for="status-0">关闭</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="status-1" name="status" value="1" <if condition="$data['status'] eq 1">checked</if>>
                    <label for="status-1">开启</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">排序：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{{$data['sort']}}" placeholder="默认为0,数值越小越靠前" id="sort" name="sort">
                <label  style="padding-left:0; color:#B3B3B3;">默认为0,数值越小排序越靠前</label>
            </div>
        </div>

        <!--search-->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">添加关联品牌：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <table width="90%" id="goods-table" style="">
                    <!-- 搜索 -->
                    <tr>
                        <td colspan="5">
                            <input type="text" class="input-text" value="" style="width:40%" placeholder="请输入品牌名称,支持模糊查询" id="brand_title" name="brand_title">
                            <button  class="btn btn-warning radius" type="button" onclick="searchBrands()"><i class="Hui-iconfont">&#xe709;</i></button>
                        <td>
                    </tr>
                    <!-- 列表 -->
                    <tr><td colspan="5" style="height:20px;"></td></tr>
                    <tr  ><th class="text-c" style="color:#B3B3B3;">选择列表</th><th class="text-c" style="color:#B3B3B3;">操作</th><th class="text-c" style="color:#B3B3B3;">关联品牌(<span id="brand_count">{{$brand_count}}</span>)</th><td></td></tr>
                    <tr>
                        <td width="30%" align="center">
                            <select name="source_select" size="15" style="width:90%" ondblclick="addToRight()" multiple="true">
                            </select>
                        </td>
                        <td width="10%" align="center">
                            <p><input type="button" value="&gt;&gt;" onclick="addAllRight()" class="btn btn-default radius" /></p>
                            <p><input type="button" value="&gt;" onclick="addToRight()" class="btn btn-default radius" /></p>
                            <p><input type="button" value="&lt;" onclick="addToLeft()" class="btn btn-default radius" /></p>
                            <p><input type="button" value="&lt;&lt;" onclick="addAllLeft()" class="btn btn-default radius" /></p>
                        </td>
                        <td width="30%" align="center">
                            <select name="target_select" multiple="true" size="15" style="width:90%" ondblclick="addToLeft()">
                                <foreach name="brandlist" item="brand">
                                    <option value="{{$brand['brand_id']}}">{{$brand['title']}}</option>
                                </foreach>
                            </select>
                        </td>
                        <td width="30%"></td>
                    </tr>
                </table>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <input class="btn btn-warning radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
                <input class="btn btn-danger radius" type="button" onclick="admin_del(this,{{$data['id']}})" value="&nbsp;&nbsp;删除&nbsp;&nbsp;">
                <button  class="btn btn-default radius" type="reset">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__EXTEND__/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__EXTEND__/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__EXTEND__/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script src="__EXTEND__/style/js/exif.js?v=b26c6d5"></script>
<script src="__EXTEND__/style/js/lrz.js?v=c105d63"></script>
<script type="text/javascript">
    function addAllRight(){
        $("select[name='source_select'] option").appendTo("select[name='target_select']");
        brandCount();
    }
    function addToRight(){
        $("select[name='source_select'] option:selected").appendTo("select[name='target_select']");
        brandCount();
    }
    function addToLeft(){
        $("select[name='target_select'] option:selected").appendTo("select[name='source_select']");
        brandCount();
    }
    function addAllLeft(){
        $("select[name='target_select'] option").appendTo("select[name='source_select']");
        brandCount();
    }
    function brandCount(){
        var brand_count = 0;
        $("select[name='target_select'] option").each(function(){
            brand_count += 1;
        });
        $("#brand_count").html(brand_count);
    }

    function searchBrands(){
        var brand_title = $("#brand_title").val();

        var select_brand = '';
        $("select[name='target_select'] option").each(function(){
            select_brand += $(this).attr("value")+",";
        });
        $.ajax({
            type: 'POST',
            url: '{{:U("Admin/Brand/searchBrand")}}',
            data: {
                title : brand_title,
                select_brand:select_brand,
            },
            dataType: 'json',
            success: function(data){
                if(data.status){
                    var brand_html = '';
                    $(data.info).each(function(i, v){
                        brand_html += '<option value="' + v.brand_id + '">' + v.title + '</option>';
                    });
                    $("select[name='source_select']").html(brand_html);
                    return;
                }else{
                    layer.msg(data.info,{icon:2,time:1000});
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });
    }

    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: '{{:U("Admin/Category/delCategory")}}',
                data: {
                    id : id
                },
                dataType: 'json',
                success: function(data){
                    if(data.status){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                        setTimeout((function() {
                            parent.window.location.href="{{:U('Admin/Category/categorylist')}}";
                        }), 500);
                    }else{
                        layer.msg(data.info, {icon:7,time:1000});
                    }
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }


    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-admin-edit").validate({
            rules:{
                status:{
                    required:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var pid = $("select[name='pid']").val();
                if(pid == 'not'){
                    layer.msg("上级分类不能选择第三级分类",{icon:5,time:1000});
                }else{
                    var select_brand = '';
                    $("select[name='target_select'] option").each(function(){
                        select_brand += $(this).attr("value")+",";
                    });
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "{{:U('Admin/Category/categoryEdit')}}" ,
                        data: {
                            select_brand:select_brand,
                        },
                        success: function(data){
                            if(data.status){
                                layer.msg(data.info,{icon:1,time:1000});
                                setTimeout((function() {
                                    parent.window.location.href="{{:U('Admin/Category/categoryList',array('id'=>$data['id']))}}";
                                }), 1500);
                            }else{
                                layer.msg(data.info,{icon:2,time:1000});
                            }
                        },
                        error: function(XmlHttpRequest, textStatus, errorThrown){
                            layer.msg('error!',{icon:5,time:1000});
                        }
                    });
                }

            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>